<html>
<head>
<title>Js til</title>
<style type="text/css">
th { text-align:left }
p { padding:0; margin:0 }
</style>

<script typw="text/javascript">
function show_repl() {
	document.getElementById('keyboard').style.visibility = 'visible';
}
</script>
</head>
<body onLoad="show_repl()">

<table border="1">
<tr valign="top">
	<td>
		<input id="keyboard" onkeyup="kbwatch(event.keyCode)" style="width:500px; visibility:hidden">
		<br>
		<div id="history"  style="overflow:scroll; height:225px; width:500px; border:1px solid red"></div>
		<button onclick="kill_all_children(document.getElementById('history')); return false">Clear</button>
		<br>
		<div id="stack"  style="overflow:scroll; height:225px; width:500px; border:1px solid green"></div>
	</td>
	<td>
		<div id="words"  style="overflow:scroll; height:500px; width:300px;"></div>
		<button onclick="kill_all_children(document.getElementById('words')); return false">Clear</button>
	</td>
	<td rowspan="2">
		<button onclick="dump_dict(cpu); return false">Dict Dump</button>
		<div id="dict" style="overflow:scroll; height:500px;width:300px"; ></div>
	</td>
</tr>
</table>

<script type="text/javascript">

var do_dump = true
var do_drawstack = true

</script>


<script src="stdlib.js" type="text/javascript">
</script>
<script src="Stack.js" type="text/javascript">
</script>
<script src="Dict.js" type="text/javascript">
</script>
<script src="Cpu.js" type="text/javascript">
</script>
<script src="Fcpu.js" type="text/javascript">
</script>


<script type="text/javascript">
function kbwatch(k) {
	if(k == 13) {
		if(cpu.kbd.value != "") {
			var a
			var i
			a = i = 10000
			cpu.cells[a++] = cpu.wa('outer')
			cpu.cells[a++] = undefined
			cpu.kbd.value = cpu.inner(i, cpu.kbd.value)
		}
	}
}


</script>


<!--

save this for later



cpu.primary(
	'tag'
	, function(c) {
		var t = c.pop();
		var e = document.createElement(t.trim());
		c.push(e);
		return c.next(c) ;
	}
)

cpu.primary(
	'[]'
	, function(c) {
		var a = new Array();
		c.push(a);
		return c.next(c) ;
	}
)

cpu.primary(
	'{}'
	, function(c) {
		c.push({});
		return c.next(c) ;
	}
)

cpu.primary(
	'![]'
	, function(c) {
		var v = c.pop();
		var k = c.pop();
		var o = c.pop();
		o[k] = v;
		return c.next(c) ;
	}
)

cpu.primary(
	'@[]'
	, function(c) {
		var k = c.pop();
		var o = c.pop();
		c.push(o[k]);
		return c.next(c) ;
	}
)


cpu.primary(
	'length'
	, function(c) {
		var a = c.pop();
		c.push(a.length);
		return c.next(c) ;
	}
)

cpu.primary(
	'apply'
	, function(c) {
		var f = c.pop();
		var args = c.pop();
		if(!isArray(args)) {
			var nargs = args;
			args = new Array(nargs);
			for(var i = 0; i < nargs; i++)
				args[i] = c.pop();
		}
		f.apply(window, args);
	
		return c.next(c) ;
	}
)

cpu.primary(
	','
	, function(c) {
		var v = c.pop();
		c.d.cells[c.d.cells.length - 1].unshift(v);
		return c.next(c) ;
	}
)

cpu.primary(
	'hd'
	, function(c) {
		var a = c.pop();
		c.push(a[0]);
		return c.next(c) ;
	}
)

cpu.primary(
	'tl'
	, function(c) {
		var a = c.pop();
		c.push(a.slice(1));
		return c.next(c) ;
	}
)

cpu.primary(
	'keys'
	, function(c) {
		var j = 0;
		var o = c.pop();
		for(var k in o) {
			c.push(k);
			j++;
		}
		c.push(j);
		return c.next(c) ;
	}
)

cpu.primary(
	'document'
	, function(c) {
		c.push(document);
		return c.next(c) ;
	}
)


cpu.primary(
	'byId'
	, function(c) {
		var i = c.pop();
		var e = document.getElementById(i);
		if(e) {
			c.push(e);
			c.push(true);
		} else {
			c.push(false);
		}
		return c.next(c) ;
	}
)


cpu.primary(
	'$call'
	, function(c) {
		var f = c.pop();
		if(isFunction(f)) {
			c.push(f());
		}
		return c.next(c) ;
	}
)

cpu.primary(
	'$calla'
	, function(c) {
		var a = c.pop();
		var f = c.pop();
		if(isFunction(f)) {
			c.push(f(a));
		}
		return c.next(c) ;
	}
)

cpu.primary(
	'.get'
	, function(c) {
		var member = c.pop();
		var obj = c.pop();
		try {
			if(member in obj) {
				c.push(obj[member]);
				c.push(true);
			} else {
				c.push(false);
			}
		} catch(e) {
			c.push(false);
		}
		return c.next(c);
	}
)

cpu.primary(
	'eval'
	, function(c) {
		var v = c.pop();
		if(v != undefined) {
			try {
				v = "v = " +v.toString();
				eval(v);
				c.push(v);
				c.push(true);
			} catch(e) {
				c.push(e);
 				c.push(false);
			}
		}
		return c.next(c) ;
	}
)

cpu.primary(
	'sqrt'
	, function(c) { // ( a - sqrt(a) );
		var v = c.pop();
		c.push(Math.sqrt(v));
		return c.next(c);
	}
)

cpu.primary(
	'sin'
	, function(c) { // ( a - sin(a) );
		var a = c.pop();
		c.push(Math.sin(a));
		return c.next(c);
	}
)

cpu.primary(
	'cos'
	, function(c) { // ( a - cos(a) );
		var a = c.pop();
		c.push(Math.cos(a));
		return c.next(c);
	}
)


cpu.primary(
	'tan'
	, function(c) {  // ( a - tan(a) );
		var a = c.pop();
		c.push(Math.tan(a));
		return c.next(c);
	}
)

cpu.primary(
	'log'
	, function(c) { // ( a - log(a) );
		var a = c.pop();
		c.push(Math.log(a));
		return c.next(c);
	}
)

cpu.primary(
	'PI'
	, function(c) { // ( - PI );
		c.push(Math.PI);
		return c.next(c);
	}
)

cpu.primary(
	'E'
	, function(c) { // ( - e );
		c.push(Math.E);
		return c.next(c);
	}
)

cpu.parse('create random " c.push(Math.random())" ,code')

cpu.parse(': $" quote token @dp byId dup if swap postpone (value) ,, then cr ; immediate')

var dummy = function() {




/*
cpu.parse(': variable constant ;code') 
*/

cpu.parse(': constant create , ;code 55 ') 


/*



cpu.parse(': recurse *ca postpone (jmp) ,, ; immediate')

cpu.parse(': .( ." )" token  @dp ;')
//cpu.parse(': `` spc token? @dp ` ; ')
//cpu.parse(': ``, `` ; ')


// cpu.parse(': variable context >vocabulary here create `c colon !CA postpone (value)  , 1 allot , postpone (semi) , >entry here 2 + swap !d ;') 


cpu.parse(': `{ ." `}" token? if @dp eval t else f then ;') 
cpu.parse(': ,`{ ." `}" token? if @dp eval , then ; immediate') // : f ,`{ function() { alert(1) ; } ; `} ;

*/
} //end dummy


-->